<?php

require_once 'PipesImpl/Database/Reflection.php';
require_once 'Pipes/Database/Reflection/Table.php';

class Pipes_Database_Reflection implements PipesImpl_Database_Reflection
{
    private $_pdo = null;
    private $_name = '';
    
    public function __construct(PipesImpl_Config $config)
    {
        $this->_pdo = $config->pdo;
    }
    
    public function fetchTable($name)
    {
        return new Pipes_Database_Reflection_Table($this, $name);
    }
    
    public function getPDO() 
    {
        return $this->_pdo;
    }
    
    public function getName() 
    { 
        
    }
    
    public function getTables()
    {
        $statement = $this->_pdo->query('SHOW TABLES');
        $rows = $statement->fetchAll(PDO::FETCH_ASSOC);
        $statement->closeCursor();
        
        $returnArray = array(); 
        foreach ($rows as $row) {
            list($colName) = each ($row);
            $tableName = $row[$colName];
            $returnArray[$tableName] = 
                new Pipes_Database_Reflection_Table($this, $tableName);
        }
        
        return $returnArray;
    }
}
